import scrapy
from qiushiPro.items import QiushiproItem


class QiushiSpider(scrapy.Spider):
    name = 'qiushi'
    # allowed_domains = ['www.xxx.com']
    start_urls = ['https://www.qiushibaike.com/text/']

    def parse(self, response):
        div_list = response.xpath('//*[@id="content"]/div/div[2]/div')
        # all_data = []
        for div in div_list:
            author = div.xpath('./div[1]/a[2]/h2/text()')[0].extract()
            content = div.xpath('./a[1]/div/span//text()').extract()
            content = ''.join(content)#列表转字符串
# print(author,content)这是基于终端指令存储的
# dic = {
# "author":author,
# "content":content
#     }
#all_data.append(dic)
#return all_data
            item = QiushiproItem()
            item['author'] = author
            item['content'] = content
            # 提交给管道
            yield item